<?php include('header.php'); ?>

<?php
$status_array = array("1"=>"已发布","0"=>"待发布");

include("/usr/local/apache2/htdocs/jibaiwang/lib/Bulletin.php");
include("/usr/local/apache2/htdocs/jibaiwang/lib/Notifaction.php");
include('log4php/Logger.php');
$cfgfile = "/usr/local/apache2/htdocs/jibaiwang/admin/conf/config.ini";
$defarray = parse_ini_file($cfgfile, 1);
$qlogtag = $defarray["Bulletin"]['qlogtag'];
Logger::configure($defarray["Bulletin"]['qlogcfg']);
$logger = Logger::getLogger($qlogtag);
$host = $defarray["Bulletin"]["host"];
$user = $defarray["Bulletin"]["user"];
$pass = $defarray["Bulletin"]["pass"];
$db = $defarray["Bulletin"]["db"];
$dbh = new Sqlexecutor($host, $user, $pass, $db);
$s = new Bulletin($dbh,$logger);
$p = new Notifaction($dbh,$logger);
if($_REQUEST["submit"] == 1)
{
    $res = $s->create($_REQUEST["Bulletin_buffer"]);
}
if($_REQUEST["op"] == "del")
{
    $res = $s->deleteByID($_REQUEST["rule_id"]);
}
if($_REQUEST["op"] == "on")
{
    $res = $s->publishByID($_REQUEST["rule_id"]);
    $res = $p->push('');
}
$list = $s->getList();
?>

<div id="myModal" class="modal hide fade">
      <div class="modal-header">
          <a class="close" data-dismiss="modal" >&times;</a>
          <h3>新建公告</h3>
      </div>
    <div class="modal-body">
    <form class="form-horizontal" target="_self">
      <div class="control-group">
          <label class="control-label" for="textarea">请输入公告信息</label>
          <div class="controls">
              <textarea class="input-xlarge" name="Bulletin_buffer" id="textarea" rows="3"></textarea>
          </div>
      </div>
    </div> 
    <div class="modal-footer">
                  <button value="1" type="submit" name="submit" class="btn btn-primary" >保存公告</button>
                  <a href="#" class="btn" data-dismiss="modal">关闭</a>
    </div>
    </form>
 </div>

            <div>
				<ul class="breadcrumb">
					<li>
						<a href="#">系统管理</a> <span class="divider">/</span>
					</li>
					<li>
						<a href="#">公告管理</a>
					</li>
				</ul>
			</div>
	                <p class="left">
                        <a data-toggle="modal" href="#myModal" class="btn btn-primary visible-desktop">添加新公告</a>
                    </p>
			<div class="row-fluid3 sortable">
				<div class="box span12">
					<div class="box-header well" data-original-title>
						<h2><i class="icon-font"></i>公告管理</h2>
<!--
						<div class="box-icon">
							<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
							<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
						</div>
-->
					</div>

                    <div class="box-content">

                    <table class="table table-striped bootstrap-datatable datatable">
                    <thead>
                    <tr>
                    <th>#</th>
                        <th>公告内容</th>
                        <th>状态</th>
                        <th>添加时间</th>
                        <th>上次发布时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                <?php       
                foreach($list as $key => $value)
                {
                    echo "<tr>";
                    echo '<td><input id="b_'.$value["id"].'" type="hidden" class="span1" name="b_id" readonly value="'.$value["id"].'">'.$value["id"  ].'</td>';
                    echo '<td><textarea readonly id="content_'.$value["id"].'" name="content" class="autogrow">'.trim($value["content"]).'</textarea></td>';
                    echo "<td>";
                    if($value["status"] == 0 ) echo '<span class="label label-warning" >'. $status_array[$value["status"]]."</span></td>";
                    if($value["status"] == 1 ) echo '<span class="label label-success" >'. $status_array[$value["status"]]."</span></td>";
                    echo "<td>".$value["insert_date"]."</td>";
                    echo "<td>".$value["publish_date"]."</td>";
                    echo "<td>";
                    echo '<div class="btn-group"><button  class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">操作<span class="caret"></span></button>';
                    echo '<ul class="dropdown-menu">';
                    echo '<li><a onclick="modify_on('.$value["id"].')"><i class="icon-ok"></i> 发布</a></li>';
                    echo '<li><a onclick="modify_del('.$value["id"].')"><i class="icon-trash"></i> 删除</a></li>';
                    echo "</div>";
                    echo "</td>";
                    echo "</tr>"; 
                }
                ?>
                    </tbody>
                    </table>

                

                    </div>
				</div><!--/span-->
			
            </div><!--/row-->
                <script type="text/javascript">
                function modify_del(id){
                    if(window.confirm("确定删除吗？")){
                        str="?op=del&rule_id="+id
                            window.open(str,'_self');
                    }
                }

                function modify_on(id){
                    if(window.confirm("确定发布吗？")){
                        str="?op=on&rule_id="+id
                            window.open(str,'_self');
                    }
                }
                </script> 
<?php include('footer.php'); ?>
